package com.pulse.base.service.impl;

import com.pulse.common.core.redis.RedisCache;
import com.pulse.base.service.IHeartbeatService;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName HeartbeatServiceImpl
 * @Description
 * @Author 陆帅
 * @Date 2024/7/15 14:41
 */
@Service("HeartbeatService")
public class HeartbeatServiceImpl implements IHeartbeatService {

    public final static Logger log = LoggerFactory.getLogger(HeartbeatServiceImpl.class);

    @Autowired
    private RedisCache redisCache;

    @Override
    public void msgHandler(String topic, MqttMessage message) {
        redisCache.setCacheObject("Heartbeat:" + topic.split("/")[2], new String(message.getPayload()), 60, TimeUnit.SECONDS);
    }
}
